//
//  CardCollectionViewCell.m
//  卡片CollectionVIew
//
//  Created by 栗子 on 2017/8/16.
//  Copyright © 2017年 http://www.cnblogs.com/Lrx-lizi/. All rights reserved.
//

#import "CardCollectionViewCell.h"
#import "ListModel.h"

@implementation CardCollectionViewCell



-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubviews];
        
    }
    return self;
}

-(void)addSubviews{
    
    self.layer.cornerRadius = 8;
    self.layer.masksToBounds=YES;
    self.backView = [[UIView alloc]initWithFrame:self.bounds];
    self.backView.backgroundColor = [UIColor whiteColor];
    self.imageIV = [[UIImageView alloc]initWithFrame:self.bounds];
    [self.contentView addSubview:self.imageIV];
    [self.contentView addSubview:self.backView];
    [self.contentView addSubview:self.headImage];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.amount];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.collectionButton];
    
}

- (UIImageView *)headImage {
    if (!_headImage) {
        _headImage = [UIImageView new];
        _headImage.backgroundColor = [UIColor yellowColor];
        _headImage.frame = CGRectMake(self.bounds.size.width/2-40, 30, 80, 80);
        _headImage.layer.masksToBounds = YES;
        _headImage.layer.cornerRadius = 40;
    }
    return _headImage;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.frame = CGRectMake(0, 130, self.bounds.size.width, 30);
        _titleLabel.font = [UIFont systemFontOfSize:21];
        _titleLabel.text = @"标题";
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

- (UILabel *)amount {
    if (!_amount) {
        _amount = [UILabel new];
        _amount.frame = CGRectMake(20, self.bounds.size.height-50, self.bounds.size.width-20, 30);
        _amount.font = [UIFont systemFontOfSize:15];
        _amount.text = @"赏金：100葡萄";
        
    }
    return _amount;
}

- (UITextView *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [UITextView new];
        _contentLabel.font = [UIFont systemFontOfSize:14];
        _contentLabel.frame = CGRectMake(20, 200, self.bounds.size.width-40, 80);
        _contentLabel.text = @"dsajkbhdkasbdlasbdlasbdlasbdalsbdasljdbasldasdalsdbassada";
        _contentLabel.editable = NO;
    }
    return _contentLabel;
}

- (UIButton *)collectionButton {
    if (!_collectionButton) {
        _collectionButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _collectionButton.frame = CGRectMake(self.bounds.size.width - 50, self.bounds.size.height - 50, 20, 20);
        [_collectionButton setImage:[UIImage imageNamed:@"Imported Layers Copy-1"] forState:UIControlStateNormal];
        [_collectionButton addTarget:self action:@selector(clickCollect) forControlEvents:UIControlEventTouchDown];
    }
    return _collectionButton;
}

- (void)setCellValue:(ListModel *)model {
    self.headImage.image = [UIImage imageNamed:model.image];
    self.titleLabel.text = model.title;
    self.contentLabel.text = model.content;
    self.amount.text = [NSString stringWithFormat:@"赏金：%@葡萄",model.amout];
    
    
}

- (void)clickCollect {
    if (self.collectionAction) {
        self.collectionAction();
    }
}
@end
